Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

frint-model

Package Overview
Dependencies
Maintainers
6
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frint-model

Model package for Frint

  • 2.8.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
140
increased by118.75%
Maintainers
6
Weekly downloads
 
Created
Source

frint-model

npm

Model package for Frint

WARNING: This package has been deprecated!

Use frint-data instead.


Guide

Installation

With npm:

$ npm install --save frint-model

Via unpkg CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.0.1/Rx.min.js"></script>

<script src="https://unpkg.com/frint-model@latest/dist/frint-model.min.js"></script>

<script>
  // available as `window.FrintModel`
</script>

Terminologies

  • Model: An object that holds data, e.g. configuration, customer information, etc.
  • attributes: The actual data in plain object, which is fed to the Model during construction.

Usage

Let's import the necessary function from the library first:

import { createModel } from 'frint-model';

Now we can create our Model:

const Shirt = createModel({
  getColor: function () {
    return this.get('color');
  },
  getSize: function () {
    return this.get('size');
  },
});

Building a new model instance object:

const shirt = new Shirt({
  color: 'blue',
  size: 'medium',
});

const color = shirt.getColor(); // blue
const size = shirt.getSize();   // medium

The model instance can also be observed for changes:

shirt.get$().subscribe(function (shirtAttributes) {
  // triggered when the model had any change
});

shirt.get$('color').subscribe(function (color) {
  // triggered when the model's `color` key changes
});

API

Model

Model

The base Model class. You can extend the base Model class freely to your own like.

Example

import { Model } from 'frint-model';

export default class Shirt extends Model {
  getColor() {
    return this.get('color');
  }

  getSize() {
    return this.get('size');
  }
}

createModel

createModel(extend)

Creates and returns an ES6 compatible class. Useful in non-ES6 compatible environments.

Arguments

  1. extend (Object): An object with the functions to extend the base Model class with.

Returns

Function: ES6 compatible class.

Example

const Shirt = createModel({
  getColor: function () {
    return this.get('color');
  },
  getSize: function () {
    return this.get('size');
  },
});

model

const model = new Model();

The Model instance

model.get

model.get(key)

Arguments
  1. key (String): Can be dot separated, like deep.nested.path. If empty, it returns all the attributes.
Returns

Any: The key's value.

model.set

model.set(key, value)

Sets the value for given key in the model.

Arguments
  1. key (String)
  2. value (Any)
Returns

void.

get$

get$(key)

Streams the model for given key.

Arguments
  1. key (String)
Returns

Observable.

Keywords

FAQs

Package last updated on 26 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc